home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / crobots8 / bishop.r next >
Text File  |  1989-12-15  |  4KB  |  107 lines

  1. /*  BISHOP        */
  2. /*                */
  3. /*    Walter D. Thompson, Jr.  */
  4. /*                */
  5. /* Strategies:    */
  6. /*                */
  7. /*  Movement: Diagonal pattern as close to the center as possible          */
  8. /*      to maximize the amount of time the robot moves at top speed.       */
  9. /*      This strategy statistically reduces the accuracy of the opponent   */
  10. /*      robots shots.  Meanwhile, a tight loop scan and fire method is     */
  11. /*      employed to shoot as often as possible at any target in range.     */
  12. /*                                                                         */
  13. /*      This is a modest enhancement to the robot file SPINNER.R           */
  14. /*                                                                         */
  15. /*                */
  16. int range;          /*  stores the range to opponent robot  */
  17. int angle;          /*  current scan direction              */
  18. int count;          /*  */
  19. int delta;          /*  */
  20. int resolution;     /*  scanning resolution, kept at maximum  */
  21. int var;            /*  */
  22. int backward_step;  /*  */
  23. /* main */
  24. main(){
  25.   int speed;        /*  driving speed, constant 100  */
  26.   int border;       /*  meters from border before starting deceleration */
  27.   angle=0;          /*  initial scan angle  */
  28.   backward_step=5;  /*  */
  29.   speed=100;        /*  initialize at maximum speed  */
  30.   resolution=10;    /*  initialize at maximum speed  */
  31.   var=resolution;
  32.   border= 55;       /*  Border distance initialized  */
  33.  
  34.     drive (180,speed);                /*  west   */
  35.     while (loc_x()>border)            /*  until border distance from wall  */
  36.     {
  37.        attack();                      /*  Continuously call attack module  */
  38.        if( !speed() )                 /*  if collision w/ robot, restart   */
  39.       drive( 180, speed );
  40.     }
  41.     drive (180,0);                    /* STOP        */
  42.     while (speed() > 49) attack();    /* wait until at turning speed       */
  43.  
  44.     drive (90,speed);                 /* north */
  45.     while (loc_y()<1000-border)       /* until border distance from wall   */
  46.     {
  47.        attack();
  48.        if( !speed() )
  49.       drive( 90, speed );
  50.     }
  51.     drive (90,0);
  52.     while (speed() > 49) attack();
  53.  
  54.     /*  Now we are in upper left corner, begin Diagonal pattern */
  55.  
  56.  while (1) {
  57.  
  58.     drive (315,speed);                /* SouthEast                   */
  59.     while (loc_y()>border && speed()>0 ) attack();
  60.     drive (315,0);
  61.     while (speed() > 49) attack();
  62.  
  63.     drive (135,speed);               /* NorthWest  */
  64.     while (loc_x()>border && speed()>0 ) attack();
  65.     drive (135,0);
  66.     while (speed() > 49) attack();
  67.  
  68.  };                        /* forever */
  69. }
  70. attack()
  71. {
  72.    int cannon_yet;       /*  Flag for Cannon: non-zero cannon has fired */
  73.    angle+=2*var;         /*  change scan angle by twice resolution      */
  74.    cannon_yet=0;         /*  initialize cannon flag to not fired        */
  75.  
  76.    /*  Loops if robot is scan range but cannon is reloading  */
  77.    while (!cannon_yet && (range = scan(angle,var ))>0 )
  78.    {
  79.       if (range<740)                       /* enemy robot sighted in range */
  80.      cannon_yet=cannon(angle,range);   /* attempt to fire cannon */
  81.       else                                 /* otherwise robot not in range */
  82.      cannon_yet=1;                     /* exit to adjust angle of scan */
  83.    }
  84.  
  85.    if (cannon_yet)                         /* robot was sited in scan range */
  86.    {
  87.       if (var>1)                           /* current resolution > 1        */
  88.       {
  89.      var>>=1;                          /* reduce resolution size        */
  90.      angle-=3*var;                     /* turn angle back (adj. for speed */
  91.      count=0;                          /* initialize search count       */
  92.       }
  93.       else                                 /* current resolution smallest   */
  94.      angle-=2*var;                     /* adjust scan angle             */
  95.    }
  96.    else                                    /* no robot in scan angle        */
  97.    {
  98.       if ((++count)==2)                    /* if searched twice             */
  99.       {
  100.      var=resolution;                   /* reset resolution to max       */
  101.      angle-=backward_step*var;         /* adjust scan angle             */
  102.       }
  103.    }
  104. }
  105.  
  106.  
  107.